<?php
namespace API\Controller;
use Think\Controller;
header("Content-type: text/json; charset=utf-8"); 
class MoviesController extends Controller {

/*1.获取所有电影信息*/
public function getMovieslist(){
        //调用模型层获取数据
        $moviesmodel=M('movies');  
        $movies=$moviesmodel->order('m_time desc')->select();
        echo json_encode($movies);
    }


/*2.获取某一条电影的详情*/
     public function getDetail(){
      $m_id=$_GET['m_id'];
      $moviesmodel=M('movies');

      $movies=$moviesmodel->table('vm_movies m,vm_type t')->where("m.m_id = $m_id and m.t_id=t.t_id")->find(); 
      $this->movies=$movies;
      echo json_encode($movies);
    } 

/*4.电影评论列表*/
 public function getMoviesCommentlist()
    {
         $comment_id=$_GET['comment_id'];
        $comment_flag=$_GET['comment_flag'];
        $commentsmodel=M('comments');
  
        $comments=$commentsmodel->table('vm_comments ct,vm_movies p,vm_users u')->where("p.m_id=$comment_id and ct.comment_id=p.m_id and ct.u_id=u.u_id and ct.comment_flag=$comment_flag")->order('com_id desc')->field('p.m_id,u.u_id,u.u_name,ct.*')->select();
        echo json_encode($comments);        
    }

/*5.搜索电影*/
 public function searchMovies(){
       $m_name=$_GET['m_name'];
       $movies = M('Movies');
       $list = $movies->where("m_name like '%$m_name%'")->select();//查询数据
       $this->ajaxReturn($list,'JSON');
      
}



    }
    

